package com.tomtop.core.doc.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.tomtop.config.WebSiteConfig;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author lei
 * @version 1.0.0
 */

@Configuration
public class Swagger2Config {
    @Profile({"prod","uat"}) @RestController static class PreventSwaggerResourcesController { @RequestMapping("/swagger-ui.html") void swaggerIndex() {} @RequestMapping("/webjars/springfox-swagger-ui/**") void swaggerResources() {} }

    @Profile({"dev","test"}) @EnableSwagger2 static class Swagger2Docket extends Docket{
		public Swagger2Docket() {
			super(DocumentationType.SWAGGER_2);
			this.apiInfo(new ApiInfoBuilder()
                    .title("api接口")
                    .description(" api接口")
                    .termsOfServiceUrl(" ")
                    .version(WebSiteConfig.getVersion())
                    .build())
            .groupName("api接口文档")
            .pathMapping("/")//最终调用接口后会和paths拼接在一起
			.select()
			.apis(RequestHandlerSelectors.basePackage("com.tomtop"))
			.paths(PathSelectors.any())
			.build();
		}}; 
}
